/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.business;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.modules.ivm.dao.business.ActivityTimeDao;
import com.neusoft.lohas.modules.ivm.entity.business.ActivityTime;

/**
 * 商圈商店Service
 * @author Jackie.Liu
 * @version 2015-01-29
 */
@Component
@Transactional(readOnly = true)
public class ActivityTimeService extends BaseService {

	@Autowired
	private ActivityTimeDao activityTimeDao;
	
	public ActivityTime get(String id) {
		return activityTimeDao.get(id);
	}
	
	public Page<ActivityTime> find(Page<ActivityTime> page, ActivityTime activityTime) {
		DetachedCriteria dc = activityTimeDao.createDetachedCriteria();
		dc.add(Restrictions.eq(ActivityTime.FIELD_DEL_FLAG, ActivityTime.DEL_FLAG_NORMAL));
		dc.add(Restrictions.eq("activity.id", activityTime.getActivity().getId()));
		dc.addOrder(Order.asc("sort"));
		return activityTimeDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(ActivityTime ActivityTime) {
		activityTimeDao.clear();
		activityTimeDao.save(ActivityTime);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		activityTimeDao.deleteById(id);
	}

}
